/**
 * Copyright (c) 2017-2020 四川智慧云天 All rights reserved.
 *
 * https://www.sczhyt.cn
 *
 * 版权所有，侵权必究！
 */

package cn.sczhyt.modules.sys.controller;

import cn.sczhyt.modules.sys.dao.SysUserRoleDao;
import cn.sczhyt.modules.sys.entity.SysUserEntity;
import cn.sczhyt.modules.sys.entity.SysUserRoleEntity;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Controller公共组件
 *
 * @author Mark sunlightcs@gmail.com
 */
public abstract class AbstractController {
	@Autowired
	SysUserRoleDao userRoleDao;

	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	protected SysUserEntity getUser() {
		return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
	}

	protected String getUserId() {
		return getUser().getUserId();
	}
	protected String getUsername() {
		return getUser().getUsername();
	}

	protected SysUserRoleEntity getUserRole() {

		return userRoleDao.selectByUserId(getUserId());
	}


	protected String getRoleId() {

		return getUserRole().getRoleId();
	}
}
